/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 *	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 * };
 */
class Solution {
public:
    int hight(TreeNode* root)
    {
        if (root == nullptr) return 0;

        int left = hight(root->left);
        int right = hight(root->right);
        return max(left, right) + 1;
    }

    bool IsBalanced_Solution(TreeNode* pRoot) {
        if (pRoot == nullptr) return true;

        int left = hight(pRoot->left), right = hight(pRoot->right);
        if (abs(left - right) > 1) return false;

        return IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right);
    }
};
